package com.welove.util;

import java.util.List;

import android.app.ActivityManager;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;

public class InternetUtil {
	private ConnectivityManager connManager;

	private State state;
	private boolean iswifi, ismobile;
	public InternetUtil(Context context) {
		super();
		
		connManager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
	}
	
	//判断网络是否可用
	public boolean  isInternet() {

		isWifi();
		is3G();
		if (!iswifi && !ismobile) {
		
			return false;
		}
		return true;
	}
	
	
	//判断是否为Wifi
	public  boolean isWifi() {
		state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
				.getState();
		if (state == State.CONNECTED) {
			iswifi = true;

		} else {
			iswifi = false;

		}
		return iswifi;
	}
	//判断是否为3g网络
	public boolean is3G() {
		state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
				.getState();
		if (state == State.CONNECTED) {
			
			ismobile = true;
			
		} else {
			ismobile = false;

		}
		return ismobile;
	}
	
	
//	public static boolean isServiceRunning(Context mContext,String className) {
//
//        boolean isRunning = false;
//        ActivityManager activityManager = (ActivityManager)
//        mContext.getSystemService(Context.ACTIVITY_SERVICE); 
//        List<ActivityManager.RunningServiceInfo> serviceList 
//                   = activityManager.getRunningServices(30);
//
//        if (!(serviceList.size()>0)) {
//            return false;
//        }
//
//        for (int i=0; i<serviceList.size(); i++) {
//            if (serviceList.get(i).service.getClassName().equals(className) == true) {
//                isRunning = true;
//                break;
//            }
//        }
//        return isRunning;
//    }
//	
}
